package com.andnnl.streamtest1;

import javafx.util.Pair;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by chenss on 2019/11/29.
 */
public class TestPattern {
    public static void main(String[] args) {
        String extNum="86123456";

        int idx = extNum.indexOf("6");
        System.out.println(idx);

        if(extNum!=null && extNum.startsWith("86")){
            extNum=extNum.trim();
            extNum=extNum.substring(extNum.length()-1);//86开头的sourceAddr,截取最后一位当作扩展号
        }
        System.out.println(extNum);

        new TestPattern().testStreamGroup();
    }

    public void testStreamGroup() {
        List<C> staffs = Arrays.asList(
                new C("A", 10), new C("A", 25), new C("A", 14),
                new C("B", 30), new C("B", 4), new C("B", 12),
                new C("C", 7), new C("C", 17), new C("C", 2),
                new C("D", 5), new C("D", 20), new C("D", 15));
        //返回A->(10,25), B->(4,30),C->(2,17) ...
//        Pair
        Map<String, List<Integer>> map = staffs.stream().collect(Collectors.toMap(c -> c.staffid
                , (C c) -> Arrays.asList(c.age, c.age)
                , (List<Integer> l1, List<Integer> l2) -> Arrays.asList(
                        (l1.get(0) > l2.get(0) ? l1.get(0) : l2.get(0))
                        , l1.get(1) < l2.get(1) ? l1.get(1) : l2.get(1))
        ));
        System.out.println(map);
    }

    static class C {
        public String staffid;
        public Integer age;

        public C() {

        }

        public C(String staffid, Integer age) {
            this.staffid = staffid;
            this.age = age;
        }
    }
}
